﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class ModifyPassword : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Session["MerchantId"] != null)
            {
                NxMerchant nxMerchant = ServiceLocator.IMerchantService.GetNxMerchant(int.Parse(Session["MerchantId"].ToString()));
                if (nxMerchant != null)
                {
                    string oldPass = MD5.MD5_32(txtOldPassword.Text.Trim());
                    if (oldPass.Equals(nxMerchant.Password))
                    {
                        string newPass = txtNewPassword.Text.Trim();
                        string rePass = txtRePassword.Text.Trim();
                        if (newPass.Equals(rePass))
                        {
                            nxMerchant.Password = MD5.MD5_32(rePass);
                            if (ServiceLocator.IMerchantService.UpdateNxMerchant(nxMerchant))
                            {
                                JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "SAVE_SUCCESSFUL") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "',null)", this.Page);
                            }
                            else
                            {
                                JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "SAVE_ERROR") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "',null)", this.Page);
                            }
                        }
                        else
                        {
                            JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "PASSWORD_DO_NOT_MATCH") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "',null)", this.Page);
                            return;
                        }
                    }
                    else
                    {
                        JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "OLD_PASSWORD_WRONG") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "',null)", this.Page);
                        return;
                    }
                }
            }
            else
            {
                JavaScript.WriteJs("jAlert('" + (String)GetGlobalResourceObject("Default", "PLEASE_LOGIN_AGAIN") + "','" + (String)GetGlobalResourceObject("Default", "NOTE") + "','Login.aspx')", this.Page);
            }
        }
    }
}
